package org.leigao.java.web.bookservice;

import org.leigao.java.web.MyActionInterface;

import com.opensymphony.xwork2.ActionContext;

public class GetBooksAction implements MyActionInterface
{
    // 该参数并不用于封装用户请求参数，而用于封装 Action 需要输出到 JSP 页面的信息； 
    private String[] books; 

    public String[] getBooks()
    {
        return books;
    }

    public void setBooks(String[] books)
    {
        this.books = books;
    }

    
    @Override
    public String execute() throws Exception
    {
        String user = (String)ActionContext.getContext().getSession().get("user"); 
        if(null != user && user.equals("scott"))
        {
            BookService bs = new BookService(); 
            setBooks(bs.getAllBooks()); 
            return SUCCESS; 
        }
        else
        {
            return LOGIN; 
        }
    }

}
